package com.work.studio.net.api;



import android.util.Log;

import com.work.studio.entitys.AttendanceStatisticsEntity;
import com.work.studio.entitys.BaseApiEntity;
import com.work.studio.entitys.CustomerEntity;
import com.work.studio.entitys.CustomerSignEntity;
import com.work.studio.entitys.CustomerVisitRntity;
import com.work.studio.entitys.DailyFinishEntity;
import com.work.studio.entitys.RankingEntity;
import com.work.studio.entitys.UpdateAppEntity;
import com.work.studio.net.RetrofitClient;
import com.work.studio.utils.TimerUtils;

import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;

public class NetProviderImpl implements NetProvider {
    RetrofitService service;
    private String TAG = this.getClass().getSimpleName();

    public NetProviderImpl() {
        service = RetrofitClient.getInstance().create(RetrofitService.class);
    }


    private Map<String, Object> createMap() {

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("CompanyId", "1052");
        map.put("Token", "b90cb5f24b85fdf2017c6d88c3404d8338ac36a5fff117406d89499a3cb8375b");
        return map;
    }

    /**
     * 考勤缺勤统计
     * @return
     */
    @Override
    public Observable<BaseApiEntity<AttendanceStatisticsEntity>> requestToday() {

        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getCurrentYMDTime());
        return service.requestToday(map);
    }

    /**
     * 销售日报完成率
     * @return
     */
    @Override
    public Observable<BaseApiEntity<DailyFinishEntity>> requestFinish() {
        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getCurrentYMDTime());
        return service.requestFinish(map);
    }


    /**
     * 客户拜访次数日统计
     * @return
     */
    @Override
    public Observable<BaseApiEntity<List<CustomerVisitRntity>>> requestVisitor() {
        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getDateBeforeWeek());
        map.put("countDate", 7);
        Log.e(TAG, "requestVisitor:"+map.toString());
        return service.requestVisitor(map);
    }

    /**
     * 获取某月份客户拜访客户排行榜
     * @return
     */
    @Override
    public Observable<BaseApiEntity<List<RankingEntity>>> requestRanking() {
        Map<String, Object> map = createMap();
        Calendar cal = Calendar.getInstance();
        map.put("Year", cal.get(Calendar.YEAR));
        map.put("Month", cal.get(Calendar.MONTH) + 1);
        return service.requestRanking(map);
    }

    /**
     * 获取某日客户实时拜访
     * @return
     */
    @Override
    public Observable<BaseApiEntity<CustomerSignEntity>> requestCustomerRecycle() {
        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getCurrentYMDTime());
//        map.put("SearchTime", "2021-07-30");
        return service.requestCustomerRecycle(map);
    }

    @Override
    public Observable<BaseApiEntity<CustomerSignEntity>> requestMapViewDatas() {
        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getCurrentYMDTime());
//        map.put("SearchTime", "2021-07-30");
        return service.requestMapViewDatas(map);
    }

    /**
     * 版本检测
     * @return
     */
    @Override
    public Observable<BaseApiEntity<UpdateAppEntity>> requestVersion() {
        return service.requestVersion();
    }

    @Override
    public Observable<BaseApiEntity<CustomerEntity>> requestCustomer() {
        Map<String, Object> map = createMap();
        map.put("SearchTime", TimerUtils.getCurrentYMDTime());
//        map.put("SearchTime", "2021-07-30");
        return service.requestCustomer(map);
    }
}

